
var Text;
var cookieValue = "";

function onerror() {
	document.getElementById("InfoList").innerHTML = "Wrong operation!";
	alert();
}

function onerror1() {
	document.getElementById("InfoList").innerHTML = "11!";
}

function onerror2() {
	document.getElementById("InfoList").innerHTML = "22!";
}

function getUserList() {
	var loader = new net.AjaxRequest("UserListServlet", dealUserList, onerror1, "GET", null);
}

function dealUserList() {
	document.getElementById("UserList").innerHTML = this.request.responseText;
}

function ta(info) {
	if (info != null && info != "")
		var loader = new net.AjaxRequest("GetInfo?info=" + info , dealInfo, onerror, "GET", null);
}

function dealInfo() {
	document.getElementById("Info").value = this.request.responseText;
	document.getElementById("Info").focus();
}

function getInfo() {
	var loader = new net.AjaxRequest("PostInfo", dealgetInfo, onerror2, "GET", null);
}

function dealgetInfo() {
	var text = this.request.responseText;
	if (text != Text) {
		Text = text;
		document.getElementById("InfoList").innerHTML = text;
		document.getElementById("InfoList").scrollTop = document.getElementById("InfoList").scrollHeight ;
	}
}

document.onkeydown = function(e) {
	var keynum = window.event ? e.keyCode : e.which;
	if (keynum == 13)
		document.getElementById("Info").blur();
}

window.onload = function() {
	readCookie("name");
	getUserList(cookieValue);
	window.setInterval("getInfo()", 200);
	window.setInterval("getUserList('')", 1000);
}

function readCookie(key) {
	var search = key + "=";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
			cookieValue = (document.cookie.substring(offset, end))
		}
	}
}